<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
        <h1 v-my-reverse="text"></h1>
        <h1 v-my-line="text"></h1>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        // 全局自定义指令
        Vue.directive('my-reverse',function(el,binding){
            el.textContent = binding.value.split('').reverse().join('');
        })
        new Vue({
            el: '#root',
            data: {
                text: 'Hello World'
            },
            // 局部自定义指令只有在这个实例里面能用
            directives: {
                'my-line': {
                    bind (el,binding){
                        el.textContent = binding.value.split('').join('-')
                    }
                }
            }
        })
    </script>
</body>
</html>